//
//  PolicyHeadView.m
//  Village
//
//  Created by longrise on 2017/9/7.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "PolicyHeadView.h"

@implementation PolicyHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        _titlelable = [[UILabel alloc] initWithFrame:CGRectMake(16*kScreenScaleX, 24*kScreenScaleY, 343*kScreenScaleX, 57*kScreenScaleY)];
        _titlelable.font = [UIFont systemFontOfSize:24*kScreenScaleX];
        _titlelable.numberOfLines = 0;
        CGFloat height = [self getHeightByWidth:_titlelable.frame.size.width title:_titlelable.text font:_titlelable.font];
        _titlelable.frame = CGRectMake(16*kScreenScaleX, 24*kScreenScaleY, 343*kScreenScaleX, height*kScreenScaleY);
        [self addSubview:_titlelable];
        
        
        
        _releseimage = [[UIImageView alloc] init];
        _releseimage.image = [UIImage imageNamed:@"release"];
        [self addSubview:_releseimage];
        [_releseimage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(20*kScreenScaleX);//使左边等于self.view的左边，间距为0
            make.top.equalTo(_titlelable.mas_bottom).offset(20*kScreenScaleY);
            make.width.mas_equalTo(7*kScreenScaleX);
            make.height.mas_equalTo(11*kScreenScaleY);
           
        }];

        self.releselable = [[UILabel alloc]init];
        self.releselable.text = @"人民日报";
        self.releselable.textColor =  [Util colorWithHexString:@"bababa"];
        self.releselable.font = [UIFont systemFontOfSize:12*kScreenScaleX];
        [ self.releselable setTextAlignment : NSTextAlignmentLeft] ;
       
        [self addSubview:self.releselable];
        
//        [self.releselable mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_releseimage.mas_right).offset(7*kScreenScaleX);//使左边等于self.view的左边，间距为0
//            make.width.mas_equalTo(60*kScreenScaleX);
//            make.height.mas_equalTo(10*kScreenScaleY);
//            make.top.equalTo(_titlelable.mas_bottom).offset(20*kScreenScaleY);
//        }];
        
        _timeimage = [[UIImageView alloc] init];
        _timeimage.image = [UIImage imageNamed:@"time"];
        [self addSubview:_timeimage];
//        [_timeimage mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_releselable.mas_right).offset(7*kScreenScaleX);//使左边等于self.view的左边，间距为0
//            make.top.equalTo(_titlelable.mas_bottom).offset(20*kScreenScaleY);
//
//            make.width.mas_equalTo(10*kScreenScaleX);
//            make.height.mas_equalTo(10*kScreenScaleY);
//
//        }];

        self.timelable = [[UILabel alloc]init];
        self.timelable.text = @"今天 10:08";
        self.timelable.textColor =  [Util colorWithHexString:@"bababa"];
        self.timelable.font = [UIFont systemFontOfSize:12*kScreenScaleX];
        [ self.timelable setTextAlignment : NSTextAlignmentLeft] ;
        
        [self addSubview:self.timelable];
        
//        [self.timelable mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_timeimage.mas_right).offset(7*kScreenScaleX);//使左边等于self.view的左边，间距为0
//            make.width.mas_equalTo(80*kScreenScaleX);
//            make.height.mas_equalTo(10*kScreenScaleY);
//            make.top.equalTo(_titlelable.mas_bottom).offset(20*kScreenScaleY);
//        }];

        
        _readimage = [[UIImageView alloc] init];
        _readimage.image = [UIImage imageNamed:@"read"];
        [self addSubview:_readimage];
//        [_readimage mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self.timelable.mas_right).offset(-1*kScreenScaleX);//使左边等于self.view的左边，间距为0
//            make.top.equalTo(_titlelable.mas_bottom).offset(20*kScreenScaleY);
//
//            make.width.mas_equalTo(12*kScreenScaleX);
//            make.height.mas_equalTo(8*kScreenScaleY);
//
//        }];
        
        self.readlable = [[UILabel alloc]init];
        self.readlable.text = @"1610";
        self.readlable.textColor =  [Util colorWithHexString:@"bababa"];
        self.readlable.font = [UIFont systemFontOfSize:12*kScreenScaleX];
        [ self.readlable setTextAlignment : NSTextAlignmentLeft] ;
        
        [self addSubview:self.readlable];
        
//        [self.readlable mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_readimage.mas_right).offset(7*kScreenScaleX);//使左边等于self.view的左边，间距为0
//            make.width.mas_equalTo(40*kScreenScaleX);
//            make.height.mas_equalTo(10*kScreenScaleY);
//            make.top.equalTo(_titlelable.mas_bottom).offset(20*kScreenScaleY);
//        }];

        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [Util colorWithHexString:@"d6d6d6"];
        [self addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(14*kScreenScaleX);//使左边等于self.view的左边，间距为0
            make.width.mas_equalTo(347*kScreenScaleX);
            make.height.mas_equalTo(0.5*kScreenScaleY);
            make.top.equalTo(_titlelable.mas_bottom).offset(45*kScreenScaleY);
        }];
        
        
        



    }
    return self;
}

- (CGFloat)getHeightByWidth:(CGFloat)width title:(NSString *)title font:(UIFont *)font
{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
    label.text = title;
    label.font = font;
    label.numberOfLines = 0;
    [label sizeToFit];
    CGFloat height = label.frame.size.height;
    return height;
}

@end

